package com.example.controller;

import com.example.dto.ArticleTagDto;
import com.example.entity.Article;
import com.example.service.ArticleService;
import com.example.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

@RequestMapping("/content/article")
@RestController
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping("")
    public ResponseResult publish(@RequestBody Article article){
        articleService.publish(article);
        return ResponseResult.okResult();
    }

    @GetMapping("list")
    public ResponseResult getList(@PathParam("pageNum") int pageNum,@PathParam("pageSize") int pageSize,@PathParam("title") String title, @PathParam("summary") String summary){
        return articleService.articleList(pageNum,pageSize,0L,title,summary);
    }

    @GetMapping("/{id}")
    public ResponseResult getArticle(@PathVariable int id){
        return articleService.getArticle(id);
    }

    @PutMapping()
    public ResponseResult updateArticle(@RequestBody ArticleTagDto article){
        return articleService.updateArticle(article);
    }

    @DeleteMapping("{ids}")
    public ResponseResult deleteArticle(@PathVariable List<Long> ids){
        return articleService.deleteArticle(ids);
    }
}
